package com.futurelight.recipes.ui.fragment;

import android.app.Application;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.viewpager2.widget.ViewPager2;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.futurelight.recipes.R;
import com.futurelight.recipes.adapter.RecipesItemAdapter;
import com.futurelight.recipes.model.Common;
import com.futurelight.recipes.model.FoodRecipes;
import com.futurelight.recipes.model.ItemViewModel;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.futurelight.recipes.model.Common.*;

public class RecipesFragment extends Fragment {
    private ItemViewModel viewModel;
    private View rootView = null;
    private Application application;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_recipes, container, false);
//        viewModel = new ViewModelProvider(this, (ViewModelProvider.Factory) ViewModelProvider.AndroidViewModelFactory.getInstance(requireActivity().getApplication())).get(ItemViewModel.class);
        application = requireActivity().getApplication();
        return rootView;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        ViewPager2 viewPager2 = rootView.findViewById(R.id.type_view_pager);
        RecipesItemAdapter recipesItemAdapter = new RecipesItemAdapter(this,requireActivity());
        viewPager2.setAdapter(recipesItemAdapter);
        TabLayout tabLayout = rootView.findViewById(R.id.tab_layout);
        new TabLayoutMediator(tabLayout, viewPager2, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(ItemViewModel.types.get(position));
            }
        }).attach();
    }
}